<template>
  <div>
    <h2>MY CART</h2>
    <div class="car_container">
      <div class="slide_box">
        <div class="cart_slide" v-for="(item, index) in list" :key="index">
          <input
            type="checkbox"
            class="check"
            @click="change(item)"
            v-model="item.choose"
          />
          <img :src="item.good.productImage" alt="" />
          <div class="dtitle">{{ item.good.productName }}</div>
          <div class="caozuo_box">
            <div>{{ item.good.salePrice }}</div>
            <div>
              <el-input-number size="mini" v-model="item.num"></el-input-number>
            </div>
            <div>
              {{ $store.getters.allPrice }}
            </div>
            <div><button @click="remove(item)">删除</button></div>
          </div>
        </div>
      </div>
      <div class="cart_bottom">
        <div>全选<input type="checkbox" v-model="checked" name="" id="" /></div>
        <div>总价:{{ $store.getters.allPrice }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
    };
  },
  methods: {
    change(item) {
      this.$store.commit("change", item.good);
    },
    remove(item){
      console.log(item);
      this.$store.commit("remove",item.good)
    }
  },
  computed: {
    checked: {
      get() {
        return this.$store.state.carlist.every((element) => {
          return element.choose == true;
        });
      },
      set(newVal){
        this.$store.commit("allChoose",newVal)
      }
    },
  },
  mounted() {
    this.list = this.$store.state.carlist;
    console.log(this.list);
  },
};
</script>

<style lang="scss">
.car_container {
  width: 800px;
  height: 390px;
  background-color: rgb(226, 226, 226);
  margin: 80px auto;
  border: 1px solid yellow;
  .slide_box {
    width: 100%;
    height: 90%;
    background-color: white;
    .cart_slide {
      width: 100%;
      height: 70px;
      border-bottom: 1px solid black;
      display: flex;
      align-items: center;
      .check {
        margin: 0 20px;
      }
      img {
        width: 50px;
        height: 50px;
      }
      .dtitle {
        width: 200px;
        margin: 0 20px;
      }
      .caozuo_box {
        width: 458px;
        // background-color: violet;
        height: 100%;
        display: flex;
        justify-content: space-around;
        align-items: center;
      }
    }
  }
  .cart_bottom {
    width: 100%;
    height: 10%;
    display: flex;
    align-items: center;
    justify-content: space-around;
  }
}
</style>
